package com.lucky.back.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.lucky.back.pojo.dto.ProductCategoryAddNewDTO;
import com.lucky.back.pojo.entity.Product;
import com.lucky.back.pojo.entity.Productcategory;
import com.lucky.back.pojo.vo.ProductCategoryListItemVO;
import com.lucky.back.pojo.vo.ProductCategoryStandardVO;
import com.lucky.back.pojo.vo.ProductStandardVO;
import com.lucky.back.service.ICategoryService;
import com.lucky.back.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Api(tags = "03.大种类管理模块")
@RestController
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    ICategoryService categoryService;

    @ApiOperation("查询分类")
    @ApiOperationSupport(order = 420)
    @GetMapping("")
    public JsonResult list(){
        List<ProductCategoryListItemVO> list = categoryService.list();
        JsonResult jsonResult = JsonResult.ok();
        jsonResult.setData(list);
        return jsonResult;
    }


    @ApiOperation("添加分类")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public JsonResult addNew(@Validated ProductCategoryAddNewDTO productCategoryAddNewDTO){
        categoryService.addNew(productCategoryAddNewDTO);
        return JsonResult.ok();
    }

    @ApiOperation("删除分类")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParam(value = "分类id",name = "id",dataType = "long",required = true)
    @PostMapping("/delete/{id}")
    public JsonResult delete(@PathVariable Long id){
        log.debug("开始处理【删除相册】的请求，参数：{}", id);
        categoryService.delete(id);
        return JsonResult.ok();
    }

    @ApiOperation("修改分类")
    @ApiOperationSupport(order = 100)
    @PostMapping("/update")
    public JsonResult update(@Validated Productcategory productcategory){
        System.out.println("conlltroller收到请求");
        categoryService.updateById(productcategory);
        return JsonResult.ok();
    }

    @ApiOperation("根据id查询详情")
    @ApiOperationSupport(order = 400)
    @GetMapping("/{id:[0-9]+}")
    public JsonResult<ProductCategoryStandardVO> getStandardById(@PathVariable Long id) {
        log.debug("开始处理【根据id查询品牌详情】的请求，参数：{}", id);
        ProductCategoryStandardVO categoryStandardVO = categoryService.getStandardById(id);
        return JsonResult.ok(categoryStandardVO);
    }
}
